﻿using Sunny.UI;
using System;
using System.Management;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 获取硬件信息
{
    public partial class FrmMain : UIForm
    {
        private readonly GetDrive getDrive = new GetDrive();

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public FrmMain()
        {
            InitializeComponent();
        }
        #endregion

        #region 单击按钮获取硬件信息事件
        /// <summary>
        /// 单击按钮获取硬件信息事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BtnGet_Click(object sender, EventArgs e)
        {
            //启用异步

            TxtUserName.Text = await Task.Run(() => getDrive.GetUserName());                 //系统登录名
            TxtComputerName.Text = await Task.Run(() => getDrive.GetComputerName());        //计算机名
            TxtSystemType.Text = await Task.Run(() => getDrive.GetSystemType());            //操作系统类型
            TxtIpAddress.Text = await Task.Run(() => getDrive.GetIpAddress());              //IP地址
            TxtMacPath.Text = await Task.Run(() => getDrive.GetMACString());                //MAC地址
            TxtCpuName.Text = await Task.Run(() => getDrive.GetCpuName());                  //CPU名称
            TxtCpuVersion.Text = await Task.Run(() => getDrive.GetCpuVersion());            //CPU版本信息
            TxtCpuFirm.Text = await Task.Run(() => getDrive.GetCpuFirm());                  //CPU厂商
            TxtCpuId.Text = await Task.Run(() => getDrive.GetCpuid());                      //CPU编号
            TxtCpuCount.Text = await Task.Run(() => getDrive.GetCpuCount().ToString());     //CPU数量
            string[] cpuhz = await Task.Run(() => getDrive.GetCpuMHZ());                    //CPU频率
            foreach (string hz in cpuhz)
            {
                TxtCpuMHZ.Text += hz + "\n";                                                //CPU频率
            }
            TxtPhysicalMemory.Text = await Task.Run(() => getDrive.GetPhysicalMemory());    //物理内存
            TxtMemorySize.Text = await Task.Run(() => getDrive.GetSizeOfMemery());          //内存大小
            TxtDiskId.Text = await Task.Run(() => getDrive.GetDiskId());                    //硬盘序列号
            TxtDiskSize.Text = await Task.Run(() => getDrive.GetSizeOfDisk());              //硬盘大小
            TxtMacAddress.Text = await Task.Run(() => getDrive.GetMacAddress());            //网卡硬件地址
            TxtBoardFirm.Text = await Task.Run(() => getDrive.GetBoardFirm());              //主板厂商
            TxtBoardId.Text = await Task.Run(() => getDrive.GetBoardId());                  //主板编号
            TxtBoardType.Text = await Task.Run(() => getDrive.GetBoardType());              //主板型号
            TxtVideoPnpId.Text = await Task.Run(() => getDrive.GetVideoPnpId());            //显卡PNP
            TxtSoundPnpId.Text = await Task.Run(() => getDrive.GetSoundPnpId());            //声卡PNP
        }
        #endregion
    }
}
